define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'contents/banner/index',
                    add_url: 'contents/banner/add',
                    edit_url: 'contents/banner/edit',
                    del_url: 'contents/banner/del',
                    table: 'banner'
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                columns: [
                    [
					 
                        {field: 'id', title: __('Id')},
                        {field: 'path', title: '图片路径', formatter: Controller.api.formatter.path, operate: false},
                        {field: 'linkurl', title: '链接地址'},
						{field: 'isshow', title: '是否显示'},
						{field: 'atime', title: '创建时间'},
                        {field: 'porder', title: '排序', sortable: true},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
				search: false,
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
			


        },
        add: function () {
            Controller.api.bindevent();
            $("#plupload-avatar").data("upload-success", function (data) {
                var url = Backend.api.cdnurl(data.url);
                $(".img-responsive").prop("src", url);
                Toastr.success("上传成功！");
            });
        },
        edit: function () {
            Controller.api.bindevent();
            // 给上传按钮添加上传成功事件
            $("#plupload-avatar").data("upload-success", function (data) {
                var url = Backend.api.cdnurl(data.url);
                $(".plupload").prop("src", url);
                Toastr.success("上传成功！");
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                path: function (value, row, index) {
                        var style = row.storage == 'upyun' ? '!/fwfh/120x90' : '';
                        return '<a href="' + row.fullurl + '" target="_blank"><img src="' + row.fullurl + style + '" alt="" style="max-height:90px;max-width:120px"></a>';
                },
                url: function (value, row, index) {
                    return '<a href="' + row.fullurl + '" target="_blank" class="label bg-green">' + value + '</a>';
                },
            }
        }

    };
    return Controller;
});